package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.annotation.AutoFill;
import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface DishMapper {

    /**
     * 根据分类id查询菜品数量
     * @param categoryId
     * @return
     */
    @Select("select count(id) from dish where category_id = #{categoryId}")
    Integer countByCategoryId(Long categoryId);

    @Insert("insert into dish(name, category_id, price, image, description, create_time, update_time, create_user, update_user)" +
            " value (#{name},#{categoryId},#{price},#{image},#{description},#{createTime},#{updateTime},#{createUser},#{updateUser})")
    @AutoFill(value = OperationType.INSERT)
    void save(Dish dish);

    void deleteById(List<Integer> idlist);

    //判断是否关联了套餐
    @Select("select count(id) from setmeal_dish where dish_id = #{id}")
    Integer countBySetmealId(Long id);

    Page<DishVO> page(DishPageQueryDTO dishPageQueryDTO);

    @Select("select * from dish where category_id = #{categoryId}")
    List<Dish> selectByCategoryId(Integer categoryId);

    DishVO getById(Long id);

    @Select("select id from dish where name = #{name}")
    Long getIdByName(String name);

    @AutoFill(value = OperationType.UPDATE)
//    @Update("update dish set name = #{name} , category_id = #{categoryId} ," +
//            "price = #{price},image = #{image},description =#{description} ," +
//            "update_user=#{updateUser},update_time=#{updateTime} where id = #{id}")
    void update(Dish dish);

    @AutoFill(value = OperationType.UPDATE)
    @Update("update dish set status = #{status},update_user=#{updateUser},update_time=#{updateTime} where id = #{id}")
    void startOrstop(Dish dish);



    List<Dish> list(Dish dish);

    //获取已停售的菜品数量
    @Select("select count(id) from dish where status = 0 ")
    Integer getStopSaleDishCount();

    //获取已起售的菜品数量
    @Select("select count(id) from dish where status = 1 ")
    Integer getStartSaleDishCount();
}
